var app = getApp();
Page({
  data: {
    url: {
      getMyCoupon: app.url.baseUrl + '/my/getaVailableCoupon',
    },
    list: [],
    pageNumber: 1
  },
  //下拉触底
  onReachBottom: function () {
    this.getQuan();
  },
  onLoad: function (options) {
    this.data.totalPrice = options.totalPrice
    this.data.productTypeNum = options.productTypeNum
    this.getQuan();
  },
  //详情
  getQuan: function (e) {
    var that = this
    app.ajax(this.data.url.getMyCoupon, { productTypeCount: this.data.productTypeNum, lowestPrice: this.data.totalPrice, pageNumber: this.data.pageNumber }, function (res) {
      var d = res.data
      if (d.code != 2000) {
        wx.showToast({
          title: d.msg,
        })
        return
      }
      if (d.data != null) {
        that.data.pageNumber += 1
        var list = that.data.list
        for (var i = 0; i < d.data.length; i++) {
          list.push(d.data[i])
        }
        that.setData({ list: list })
      }
    })
  },
  use: function (e) {
    var index = e.currentTarget.dataset.index
    var obj = this.data.list[index]
    app.param.scanCallCoupon = { id: obj.id, money: obj.couponPrice }
    wx.navigateBack({

    })
  }
})